package cn.com.dwr.mapper;

import cn.com.dwr.entity.AppProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
* @author 邓文润
* @description 针对表【app_product】的数据库操作Mapper
* @createDate 2023-12-12 07:13:55
* @Entity cn.com.dwr.entity.AppProduct
*/
public interface AppProductMapper extends BaseMapper<AppProduct> {

    @Update("update app_product set stock = stock - #{quantity} where id = #{productId} and stock >= #{quantity}")
    int reduceStock(@Param("productId") Long productId, @Param("quantity") Integer quantity);

    @Update("update app_product set stock = stock + #{quantity} where id = #{productId} and stock >= 0")
    int releaseStock(@Param("productId") Long productId, @Param("quantity") Integer quantity);
}




